package com.example.demo.controller;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.demo.dao.TestDao;
import com.example.demo.entity.Test;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author yzp
 * @date 2021/5/14 14:28
 */
@Slf4j
@RestController
@RequestMapping("test")
public class TestController {
    @Autowired
    private TestDao testDao;
    @Autowired
    private JdbcTemplate jdbcTemplate;

    @DS("#header.tenantId")
    @GetMapping("test")
    public void test() throws Exception {
        List<Test> testList = testDao.selectList(new LambdaQueryWrapper<>());
        log.info(new ObjectMapper().writeValueAsString(testList));
    }

    @GetMapping("test2")
    public void test2() {
        jdbcTemplate.execute("create database test2");

    }
}
